package com.example.zg6.fragment;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.navigation.NavController;
import androidx.navigation.fragment.NavHostFragment;

import android.content.Intent;
import android.os.Bundle;
import android.view.MenuItem;

import com.blankj.utilcode.util.AppUtils;
import com.example.zg6.R;
import com.example.zg6.bottomnavgation.AppBottomView;
import com.example.zg6.bottomnavgation.NavigationBuilder;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.umeng.socialize.UMShareAPI;

import update.UpdateAppUtils;

public class FrameActivity extends AppCompatActivity {
    private AppBottomView appBottomView;
    private NavHostFragment fragment;
    private NavController controller;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_frame);
        appBottomView = findViewById(R.id.bottom_nav);
        fragment = (NavHostFragment) getSupportFragmentManager().findFragmentById(R.id.primary_fragment_container);
        controller = fragment.getNavController();
        new NavigationBuilder().create(this, getSupportFragmentManager(), controller, fragment.getId());
        appBottomView.setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() {
            @Override
            public boolean onNavigationItemSelected(@NonNull MenuItem item) {
                controller.navigate(item.getItemId());
                return true;
            }
        });
        if (AppUtils.getAppVersionCode()<2){
            //更新下载地址
            UpdateAppUtils.getInstance().apkUrl("")
                    .updateTitle("当前版本可更新到"+AppUtils.getAppVersionName())
                    .updateContent("新版本增加了新功能")
                    .update();
        }


    }

    @Override
    protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        UMShareAPI.get(this).onActivityResult(requestCode, resultCode, data);
    }
}